package com.javacode2018.demo3;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.support.TransactionTemplate;

@Component
public class UserService implements IUserService {
    @Autowired
    protected UserDao userDao;

    @Autowired
    protected TransactionTemplate transactionTemplate;

    public void insert() {
        transactionTemplate.executeWithoutResult(action -> {
            this.userDao.insert("tom1");
            this.insert1();
            System.out.println("哈哈哈!");
        });
    }

    public void insert1() {
        transactionTemplate.executeWithoutResult(action -> {
            this.userDao.insert("tom2");
        });
    }
}
